package demo2;

public class Main {
    public static void main(String[] args) {
        Work work = new Work();
        work.setHour(9);
        work.WriteProgram();
        work.setHour(10);
        work.WriteProgram();
        work.setHour(12);
        work.WriteProgram();
        work.setHour(13);
        work.WriteProgram();
        work.setHour(14);
        work.WriteProgram();
        work.setHour(17);
        work.WriteProgram();
        work.setHour(19);
        work.WriteProgram();
        work.setHour(22);
        work.WriteProgram();
    }
}

abstract class State{
    public abstract void WriteProgram(Work work);
}

//上午工作状态
class ForenoonState extends State{
    @Override
    public void WriteProgram(Work work) {
        if(work.getHour()<12){
            System.out.println("当前时间:"+work.getHour()+"点 上午工作,精神百倍");
        }else {
            work.SetState(new NoonState());//超过12点
            work.WriteProgram();
        }
    }
}

//中午工作状态
class NoonState extends State{
    @Override
    public void WriteProgram(Work work) {
        if(work.getHour()<13){
            System.out.println("当前时间:"+work.getHour()+"点 饿了,午饭,困了,午休");
        }else{
            work.SetState(new AfternoonState());
            work.WriteProgram();
        }
    }
}
class AfternoonState extends State{
    @Override
    public void WriteProgram(Work work) {
        if(work.getHour()<17){
            System.out.println("当前时间:"+work.getHour()+"点 下午状态还不错，继续努力");
        }else {
            work.SetState(new EveningState());
            work.WriteProgram();
        }
    }
}
//晚间状态
class EveningState extends State{
    @Override
    public void WriteProgram(Work work) {
        if(work.isFinish()){
            work.SetState(new RestState());
            work.WriteProgram();
        }else {
            if(work.getHour()<21){
                System.out.println("当前时间:"+work.getHour()+"点 加班哦 疲劳之极");
            }else {
                work.SetState(new SleepingState());
                work.WriteProgram();
            }
        }
    }
}
//睡觉状态
class SleepingState extends State{
    @Override
    public void WriteProgram(Work work) {
        System.out.println("当前时间:"+ work.getHour()+"点 不行了睡着了");

    }
}
//下班休息状态
class RestState extends State{
    @Override
    public void WriteProgram(Work work) {
        System.out.println("当前时间:"+ work.getHour()+"点 下班回家了");
    }
}

class Work{
    private State current;
    public Work(){
        current = new ForenoonState();
    }
    private double hour;

    public double getHour() {
        return hour;
    }

    public void setHour(double hour) {
        this.hour = hour;
    }
    private boolean finish = false;
    public void SetState(State state){
        current = state;
    }
    public void WriteProgram(){
        current.WriteProgram(this);
    }

    public boolean isFinish() {
        return finish;
    }

    public void setFinish(boolean finish) {
        this.finish = finish;
    }
}